package com.w.tank;

public class TankBullectColl implements Collider {

    @Override
    public boolean collide(GameObject g1, GameObject g2) {
        if(g1 instanceof Tank && g2 instanceof Bullet){
            Tank tk1 = (Tank)g1;
            Bullet tk2 = (Bullet)g2;
            if(tk1.rect.intersects(tk2.rect)){
                if(tk1.getGroup() != tk2.getGroup()){
                    tk2.destory();
                    tk1.destory();
                    new Explore(tk1.getX() + Tank.WIDTH/2 - Explore.WIDTH/2, tk1.getY() + Tank.HEIGHT/2 - Explore.WIDTH/2);
                    return true;

                }

            }

        }else if(g1 instanceof Bullet && g2 instanceof Tank){
            Tank tk1 = (Tank)g2;
            Bullet tk2 = (Bullet)g1;
            if(tk1.rect.intersects(tk2.rect)){
                if(tk1.getGroup() != tk2.getGroup()){
                   tk2.destory();
                    tk1.destory();
                    new Explore(tk1.getX() + Tank.WIDTH/2 - Explore.WIDTH/2, tk1.getY() + Tank.HEIGHT/2 - Explore.WIDTH/2);
                    return true;
                }


            }
        }

        return false;


    }
}
